package main

import (
	"cloud-storage/lib"
	"cloud-storage/model/mysql"
	"cloud-storage/model/redis"
	"cloud-storage/pkg/logger"
	"cloud-storage/router"
	"go.uber.org/zap"
	"net/http"
)

func main() {
	//初始化配置文件
	lib.InitConfig()
	//初始化日志库
	logger.InitLog()
	//初始化mysql
	mysql.InitMysql()
	//关闭数据库连接
	defer mysql.Close()
	//连接redis
	redis.InitRedis()
	//初始化路由
	r := router.InitRouter()
	s := &http.Server{
		Addr:         lib.ServerSetting.Address,
		Handler:      r,
		ReadTimeout:  lib.ServerSetting.ReadTimeout,
		WriteTimeout: lib.ServerSetting.WriteTimeout,
	}
	zap.L().Info("server run success on ", zap.String("address", lib.ServerSetting.Address))
	_ = s.ListenAndServe()
}
